<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Euphio Show Management</title>

<script language="javascript" src="jquery-ui-1.8.14.custom/js/jquery-1.5.1.min.js"></script>
<script language="javascript" src="jquery-ui-1.8.14.custom/js/jquery-ui-1.8.14.custom.min.js"></script>
<link rel="stylesheet" href="jquery-ui-1.8.14.custom/css/hot-sneaks/jquery-ui-1.8.15.custom.css" type="text/css">
<link rel="stylesheet" href="css/customizations.css" type="text/css">
<link media="handheld, only screen and (max-width: 480px), only screen and (max-device-width: 480px)" href="css/mobile.css" type="text/css" rel="stylesheet" />
<!--[if IEMobile]>
<link rel="stylesheet" type="text/css" href="mobile.css" media="screen" />
<![endif]-->

<meta http-equiv="x-ua-compatible" content="IE=9">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable"      content="yes" />
<meta name="apple-mobile-web-app-status-bar-style"      content="black" />

<script language="javascript" >
if (navigator.platform == 'iPad')
{
	var filename = 'ipadstartup.png';
}
else
{
	var filename = 'startup.png';
}
document.write('<link rel="apple-touch-startup-image" ' + 'href="images/' + filename + '" />' );
</script>

</head>

<?php
//Include PHP Resources
include 'includes.php';
include 'config.php';
include 'functions.php';
?>

<?php 
function processPageLoad()
{
?>
	<div id="processing" class="processing">
		<div class="ui-widget">
		<div class="ui-widget-header">Euphio</div>
		<div class="ui-widget-content" style="text-align:center">
		<span style="vertical-align:top; text-align:center;">Processeing Request&nbsp;&nbsp;</span>
		<img src="images/loader.gif" height="25" style="flot:right" />
		</div>
		</div>
	</div>

	<!-- Page Wrapper -->
	<div id="wrapper" class="wrapper">

	<!-- Title -->
	<div class="ui-widget">
	<div class="ui-widget-header">Euphio</div>
	</div>
<?php
	
	//Authenticate with hardcoded creds and instantiate service
	global $username, $password;
	$service = newservice($username, $password);
	
	//Get Calendar List as $listFeed
	try {
		$listFeed= $service->getCalendarListFeed();
	} catch (Zend_Gdata_App_Exception $e) {
		echo "Error: " . $e->getMessage();
	}
	
	//Widget Header
	foreach ($listFeed as $calendar) {
		if ($calendar->title == 'Shows')
		{
			$url = $calendar->link[0]->href;
		}
	}
	
	//Run post back actions i.e. Delete, Add
	
	runpostbackactions($url, $service);
	
	//Get calendar list as $listFeed
	try {
		$listFeed= $service->getCalendarListFeed();
	} catch (Zend_Gdata_App_Exception $e) {
		echo "Error: " . $e->getMessage();
	}
	
	//Get Events for Calendar
	$query = $service->newEventQuery($url);
	$query->setUser(NULL);
	$query->setVisibility(NULL);
	$query->setProjection(NULL);
	$query->setOrderby('starttime');
	$query->setFutureevents('true');
	
	// Execute query and get results as $eventFeed
	try {
		$eventFeed = $service->getCalendarEventFeed($query);
	} catch (Zend_Gdata_App_Exception $e) {
		echo "Error: " . $e->getMessage();
	}
	
	?>
	
	<div id="alertmessagediv"></div>
	
	<DIV id=accordion>
	<H3><A href="#">Shows</A></H3>
	<DIV><P>
	
	<!-- Shows Widget -->
	
	<?php
	// Iterate through the list of events
	foreach ($eventFeed as $event) {
		//Get full date and time for event
		$datestring = $event->when[0]->startTime;
		//Instantiate DateTime object as $date
		$date = new DateTime($datestring);
	?>
	
		<div>
		<!-- Output event info -->
		<?php echo '<b>' . $event->title . '</b><br/>' . $date->format('l') . 
		' &#8226; ' . $date->format('n') . ' / ' . $date->format('j') . 
		' &#8226; ' . $date->format(' g:ia') .
		'<br />' . $event->where[0]; ?>
		<!-- Delete Event Button -->
		<form method="post" action="<?php $_SERVER["PHP_SELF"] ?>" style="display:inline;" onsubmit="return validateForm('deleteshow')">
		<input type="hidden" name="action" value="deleteevent" />
		<input type="hidden" name="eventid" value="<?php echo $event->id ?>" />
		<br/><button type="submit" name="Submit">Delete Show</button>
		</form>
		</div>
				
	<?php } ?>
	
	<!-- End Shows Widget -->
	</P></DIV>
	<H3><A href="#">Add New Show</A></H3>
	<DIV><P>

	<!-- Add Show Widget -->
	
	<!-- Add Show Form -->
	<form name="addshow" method="post" action="<?php $_SERVER["PHP_SELF"] ?>" onsubmit="return validateForm('addshow')">
	<input type="hidden" name="action" value="addevent">
	<input type="hidden" name="url" value="<?php echo $url ?>">
	<div>
	<?php $bands = getbands($service); ?>
	<select name="title">
	<option value="ChooseB">Choose Band...</option>
	<?php 
	foreach ($bands as $band)
	{ 
		if($band != NULL || $band != "")
		{?>
		<option value="<?php echo $band ?>"><?php echo $band ?></option>
	<?php } 
	} ?>
	</select>
	</div>
	<br />
	<div>
	<?php $locations = getlocations($service); ?>
	<select name="where">
	<option value="ChooseV">Choose Venue...</option>
	<?php
	foreach ($locations as $location)
	{	
		$venue = explode("#@", $location); 
		if($venue[0] != NULL || $venue[0] != '')
		{?>
		<option value="<?php echo $venue[0] . ' - ' . $venue[1] . ', ' . $venue[2]; ?>"><?php echo $venue[0] . ' - ' . $venue[1] . ', ' . $venue[2]; ?></option>
	<?php }
	} ?>
	</select>
	</div>
	<br />
	<div> 
	<input type="hidden" id="datetimeinput" class="date" name="startdate" value="Choose Date..." onclick="$(function(){$('#ui-datepicker-div').css('left','0px'); $('.ui-datepicker').css('width', '11em');)};" >
	<input type="text" disabled id="datedisplay" class="date" name="displaydate" value="Choose Date..." >
	</div>
	<br/>
	<div>
	<select name="hour">
	<option value="12">12</option>
	<?php 
	$i=1;
	while ($i < 12)
	{
		if($i < 10)
		{
			echo '<option value="0' . $i . '">' . $i . '</option>';
		}
		else 
		{
			echo '<option value="' . $i . '">' . $i . '</option>';
		}
		$i++;
	}
	?>
	</select>
	:
	<select name="minutetens">
	<?php 
	$i=0;
	while ($i <= 5)
	{
		echo '<option value="' . $i . '">' . $i . '</option>';
		$i++;
	}
	echo ' : ';
	?>
	</select>
	<select name="minuteones">
	<?php 
	$i=0;
	while ($i <= 9)
	{
		echo '<option value="' . $i . '">' . $i . '</option>';
		$i++;
	}
	echo ' : ';
	?>
	</select>
	<select name="ampm">
	<option value="pm">PM</option>
	<option value="am">AM</option>
	</select>
	</div>
	<br/>
	<div>
	<button type="submit" name="Submit">Add Show</button>
	</form>
	</div>
	
	<!-- End Add Show Widget -->
	
	</P></DIV>
	<H3><A href="#">Add/Remove Bands</A></H3>
	<DIV><P>
	
	<!-- Manage Bands Widget -->
	
	<!-- Add Band Form -->
	<div>
	<form name="addband" method="post" action="<?php $_SERVER["PHP_SELF"] ?>" onsubmit="return validateForm('addband')">
	<input type="hidden" name="action" value="addband">
	<input type="hidden" name="url" value="<?php echo $url ?>">
	<input type="text" name="newband" value="Band Name" onfocus="removetext(this, event, 'Band Name')" onblur="removetext(this, event, 'Band Name')">
	<button type="submit" name="Submit">Add Band</button><br/>
	</form>
	</div>
	<!-- End Add Band Form -->
	<br />
	<!-- Delete Band Form -->
	<div>
	<form name="deleteband" method="post" action="<?php $_SERVER["PHP_SELF"] ?>" onsubmit="return validateForm('deleteband')">
	<input type="hidden" name="action" value="deleteband">
	<input type="hidden" name="url" value="<?php echo $url ?>">
	<?php $bands = getbands($service); ?>
	<select name="title">
	<option value="ChooseB">Choose Band...</option>
	<?php 
	foreach ($bands as $band)
	{ 
		if($band != NULL || $band != "")
		{?>
		<option value="<?php echo $band ?>"><?php echo $band ?></option>
	<?php } 
	} ?>
	</select>
	<button type="submit" style="margin-left:0px;" name="Submit">Delete Band</button><br/>
	</form>
	</div>
	
	<!-- End Delete a Band Form -->
	
	<!-- End Manage Bands Widget -->
	</P></DIV>
	<H3><A href="#">Add/Remove Venues</A></H3>
	<DIV><P>

	<!-- Manage Locations Widget -->
	
	<!-- Add Location Form -->
	
	<div>
	<form name="addvenue" method="post" action="<?php $_SERVER["PHP_SELF"] ?>" onsubmit="return validateForm('addvenue')">
	<input type="hidden" name="action" value="addlocation">
	<input type="hidden" name="url" value="<?php echo $url ?>">
	<input type="text" id="newName" name="newname" value="Venue Name" onfocus="removetext(this, event, 'Venue Name')" onblur="removetext(this, event, 'Venue Name')">
	<br /><br />
	<input type="text" id="newCity" name="newcity" value="City" onfocus="removetext(this, event, 'City')" onblur="removetext(this, event, 'City')">
	<br /><br />
	<select id="newState" name="newstate" size="1">
	<option value="TX">Texas</option>
	<option value="AL">Alabama</option>
	<option value="AK">Alaska</option>
	<option value="AZ">Arizona</option>
	<option value="AR">Arkansas</option>
	<option value="CA">California</option>
	<option value="CO">Colorado</option>
	<option value="CT">Connecticut</option>
	<option value="DE">Delaware</option>
	<option value="FL">Florida</option>
	<option value="GA">Georgia</option>
	<option value="HI">Hawaii</option>
	<option value="ID">Idaho</option>
	<option value="IL">Illinois</option>
	<option value="IN">Indiana</option>
	<option value="IA">Iowa</option>
	<option value="KS">Kansas</option>
	<option value="KY">Kentucky</option>
	<option value="LA">Louisiana</option>
	<option value="ME">Maine</option>
	<option value="MD">Maryland</option>
	<option value="MA">Massachusetts</option>
	<option value="MI">Michigan</option>
	<option value="MN">Minnesota</option>
	<option value="MS">Mississippi</option>
	<option value="MO">Missouri</option>
	<option value="MT">Montana</option>
	<option value="NE">Nebraska</option>
	<option value="NV">Nevada</option>
	<option value="NH">New Hampshire</option>
	<option value="NJ">New Jersey</option>
	<option value="NM">New Mexico</option>
	<option value="NY">New York</option>
	<option value="NC">North Carolina</option>
	<option value="ND">North Dakota</option>
	<option value="OH">Ohio</option>
	<option value="OK">Oklahoma</option>
	<option value="OR">Oregon</option>
	<option value="PA">Pennsylvania</option>
	<option value="RI">Rhode Island</option>
	<option value="SC">South Carolina</option>
	<option value="SD">South Dakota</option>
	<option value="TN">Tennessee</option>
	<option value="UT">Utah</option>
	<option value="VT">Vermont</option>
	<option value="VA">Virginia</option>
	<option value="WA">Washington</option>
	<option value="WV">West Virginia</option>
	<option value="WI">Wisconsin</option>
	<option value="WY">Wyoming</option>
	</select>
	</div>
	<div>
	<button type="submit" name="Submit">Add Venue</button><br/>
	</form>
	</div>
	<!-- End Add Location Form -->
	<br /><br />
	<!-- Delete Location Form -->
	<div>
	<form name="deletevenue" method="post" action="<?php $_SERVER["PHP_SELF"] ?>" onsubmit="return validateForm('deletevenue')">
	<input type="hidden" name="action" value="deletelocation">
	<input type="hidden" name="url" value="<?php echo $url ?>">
	<?php $locations = getlocations($service); ?>
	<select name="where">
	<option value="ChooseV">Choose Venue...</option>
	<?php
	foreach ($locations as $location)
	{	
		$venue = explode("#@", $location); 
		if($venue[0] != NULL || $venue[0] != '')
		{?>
		<option value="<?php echo $venue[0] . ' - ' . $venue[1] . ', ' . $venue[2]; ?>"><?php echo $venue[0] . ' - ' . $venue[1] . ', ' . $venue[2]; ?></option>
	<?php }
	} ?>
	</select>
	<button type="submit" style="margin-left:0px;" name="Submit">Delete Venue</button><br/>
	</form>
	</div>
	
	<!-- End Delete Location Form -->
	
	
	<!-- End Manage Locations Widget -->
	</P></DIV>
</DIV>
	

	
	
	
	</div>
<?php } ?>


<?php
processPageLoad();
?>

<!-- jQuery document ready function -->
<script type="text/javascript">
	$(document).ready(function () {
		//Initialize jQuery DateInput
		$(function() {
			$( "#accordion" ).accordion({ 
				autoHeight: false, 
				clearStyle: true, 
				icons: {  'header': 'ui-icon-triangle-1-e', 'headerSelected': 'ui-icon-triangle-1-s'  },
				navigation: true,
				collapsible: true
			});
		});
		$( "#datetimeinput" ).datepicker({ 
			minDate: +0,
			showOn: "button",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true,
			altField: '#datedisplay'
		});
		if (navigator.platform == 'iPhone')
		{
			$(".ui-datepicker-trigger").click(function(event) {
				$('.ui-datepicker-header').css("padding-left","20px");
				$('#ui-datepicker-div').css("left","0px");
				});
		}
		if (navigator.userAgent.indexOf('iPhone') != -1) {
	        addEventListener("load", function() {
	                setTimeout(hideURLbar, 0);
	        }, false);
		}	
	});

	function hideURLbar() {
        window.scrollTo(0, 1);
	}
	
	function removetext(txt, event, value){
		//if textbox char length 0, onblur set to value 0
        if (txt.value.length == 0) {
           txt.value = value;
        }
        //if textbox char length = 0, onfocus set to value empty
        else if (txt.value == value) {
           txt.value = "";
        }
        else if (event.type == "focus" && txt.value != value)
        {
           txt.select();
        }
	}

	function validateForm(form)
	 {
		 if(form == "addshow")
		 {
	 		var x=document.forms[form]["title"].value;
	 		if (x==null || x=="" || x=="ChooseB")
	   		{
	   			showalert("Please choose a band.");
	   			return false;
	   		}
	 		var x=document.forms[form]["where"].value;
	 		if (x==null || x=="" || x=="ChooseV")
	   		{
	   			showalert("Please choose a venue.");
	   			return false;
	   		}
	 		var x=document.forms[form]["datetimeinput"].value;
	 		if (x==null || x=="" || x=="Choose Date...")
	   		{
	   			showalert("Please choose a date.");
	   			return false;
	   		}
		 }
		 else if(form == "addband")
		 {
		 	var x=document.forms[form]["newband"].value;
	 		if (x==null || x=="" || x=="Band Name")
	   		{
	   			showalert("Please enter a band name.");
	   			return false;
	   		}
		 }
		 else if(form == "deleteband")
		 {
		 	var x=document.forms[form]["title"].value;
	 		if (x==null || x=="" || x=="ChooseB")
	   		{
	   			showalert("Please choose a band.");
	   			return false;
	   		}
		 }
		 else if(form == "addvenue")
		 {
		 	var x=document.forms[form]["newName"].value;
	 		if (x==null || x=="" || x=="Venue Name")
	   		{
	   			showalert("Please enter a venue name.");
	   			return false;
	   		}
	 		var x=document.forms[form]["newCity"].value;
	 		if (x==null || x=="" || x=="City")
	   		{
	   			showalert("Please enter a city.");
	   			return false;
	   		}
		 }
		 else if(form == "deletevenue")
		 {
		 	var x=document.forms[form]["where"].value;
	 		if (x==null || x=="" || x=="ChooseV")
	   		{
	   			showalert("Please choose a venue.");
	   			return false;
	   		}
		 }
		 $('#wrapper').fadeOut('slow', function() {
			 $('#processing').fadeIn('slow', function() {
		  });
		});
		 
	 }

	function showalert(message)
	{
		alertdiv = document.getElementById('alertmessagediv');
		if(alertdiv)
		{
			messagehtml = '<div class="ui-widget alert"><DIV id="alertmessage" style="PADDING-BOTTOM: 0px; PADDING-LEFT: 0.7em; PADDING-RIGHT: 0.7em; PADDING-TOP: 0px" class="ui-state-error ui-corner-all"><P><SPAN style="FLOAT: left; MARGIN-RIGHT: 0.3em" class="ui-icon ui-icon-alert"></SPAN><STRONG>' + message + '</STRONG></P></DIV></div>';
			alertdiv.innerHTML = messagehtml;
			$("#alertmessage").delay(5000).fadeTo(400,0);
		}
	}
	
</script>

</body>
</html>